﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GurLoader.ViewModel;
using Moq;
using NUnit.Framework;

namespace GurLoaderWPF.Test.ViewModel
{ 
    [TestFixture]
    public class CaptureAreaViewModelTests
    {

        [Test]
        public void CreateInstanceTest()
        {
            ImageSource imageSource  = new BitmapImage();
            var vm = new CaptureAreaViewModel(imageSource);

            Assert.IsNotNull(vm);

            Assert.AreEqual(imageSource, vm.Image);
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void CreateInstanceNullImageTest()
        {
            var vm = new CaptureAreaViewModel(null);
        }

        [Test]
        public void AreaSelectedEventTest()
        {
            ImageSource imageSource = new BitmapImage();
            var vm = new CaptureAreaViewModel(imageSource);

            Assert.IsNotNull(vm);

            ManualResetEvent mre = new ManualResetEvent(false);
            vm.AreaSelected += (sender, args) => mre.Set();

            vm.AreaSelectedCommand.Execute(null);
            Assert.IsTrue(mre.WaitOne(1000*3), "Timeout waiting for area selected event to fire.");
        }

        [Test]
        public void RequestCloseEventTest()
        {
            ImageSource imageSource = new BitmapImage();
            var vm = new CaptureAreaViewModel(imageSource);

            Assert.IsNotNull(vm);

            ManualResetEvent mre = new ManualResetEvent(false);
            vm.RequestClose += (sender, args) => mre.Set();

            vm.AreaSelectedCommand.Execute(null);
            Assert.IsTrue(mre.WaitOne(1000 * 3), "Timeout waiting for request close event to fire.");
        }
    }
}
